package com.biz.primus.app.erpbridge;

import com.biz.primus.app.erpbridge.config.BaseConfiguration;
import com.biz.primus.app.erpbridge.config.Swagger2Configuration;
import com.biz.primus.app.erpbridge.interceptor.AuthInterceptor;
import com.biz.primus.app.erpbridge.interceptor.RepeatedRequestInterceptor;
import com.biz.primus.app.erpbridge.stream.GeoUpdateSink;
import com.biz.primus.app.erpbridge.stream.OmsCollectionSource;
import com.biz.primus.app.erpbridge.stream.OmsStateSink;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author yanweijin
 * @date 2017/11/3
 */

@SpringCloudApplication
@EnableFeignClients
@EnableBinding({
        GeoUpdateSink.class, OmsCollectionSource.class, OmsStateSink.class
})
@Import({
        BaseConfiguration.class,
        Swagger2Configuration.class,
})

public class ErpBridgeApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
        new SpringApplicationBuilder(ErpBridgeApplication.class).web(true).run(args);
    }

    @Autowired
    AuthInterceptor authInterceptor;

    @Autowired
    RepeatedRequestInterceptor repeatedRequestInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor).addPathPatterns("/");
        registry.addInterceptor(repeatedRequestInterceptor).addPathPatterns("/");
    }
}
